local qilv = fk.CreateSkill {
  name = "lingling__qilv",
}

Fk:loadTranslationTable{
  ["lingling__qilv"] = "七律",
  [":lingling__qilv"] = "每回合每种牌名限一次，你可以将任意张点数之和为7的牌当【无懈可击】外的任意普通锦囊牌使用，"..
  "若用于转化的牌多于两张，你摸一张牌。",

  ["#lingling__qilv"] = "七律：将点数之和为7的牌当任意普通锦囊牌使用",
}

qilv:addEffect("viewas", {
  pattern = "^nullification|.|.|.|.|trick",
  prompt = "#lingling__qilv",
  interaction = function(self, player)
    local all_names = Fk:getAllCardNames("t")
    local names = player:getViewAsCardNames(qilv.name, all_names, nil,
      table.connect(player:getTableMark("lingling__qilv-turn"), {"nullification"}))
    if #names == 0 then return end
    return UI.CardNameBox { choices = names, all_choices = all_names }
  end,
  handly_pile = true,
  card_filter = function(self, player, to_select, selected)
    local num = 0
    for _, id in ipairs(selected) do
      num = num + Fk:getCardById(id).number
    end
    return num + Fk:getCardById(to_select).number <= 7
  end,
  view_as = function (self, player, cards)
    if self.interaction.data == nil then return end
    local num = 0
    for _, id in ipairs(cards) do
      num = num + Fk:getCardById(id).number
    end
    if num ~= 7 then return end
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcards(cards)
    card.skillName = qilv.name
    return card
  end,
  before_use = function (self, player, use)
    player.room:addTableMark(player, "lingling__qilv-turn", use.card.trueName)
  end,
  after_use = function (self, player, use)
    if #use.card.subcards > 2 and not player.dead then
      player:drawCards(1, qilv.name)
    end
  end,
  enabled_at_response = function(self, player, response)
    return not response and
      #player:getViewAsCardNames(qilv.name, Fk:getAllCardNames("t"), nil,
        table.connect(player:getTableMark("lingling__qilv-turn"), {"nullification"})) > 0
  end,
})

qilv:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, "lingling__qilv-turn", 0)
end)

return qilv
